// 加载层
var loadIndex = layer.load(1, { shade: [0.5, '#fff'] })
    // 定义一个async异步函数
async function getIndex() {
    var kill = document.querySelector('.miaosha');
    var kill_list = await pAjax({
        url: '../server/kill.php',
        data: { pid: 2 }
    });
    var { data } = kill_list;
    var str = '';
    str = ` <div>
    
</div>`
    for (var i = 0; i < data.length; i++) {
        str += `
    <div>
    <img src="${data[i].imgpath}" alt="">
    <b>${data[i].name}</b>
    <span>￥${data[i].current}</span>
    <s>￥${data[i].price}</s>
    <p>${data[i].state}</p>
</div>`
    }
    kill.innerHTML = str;

    //********************************************** */
    //cent渲染
    var foot = document.querySelector('.foot');
    var foot_list = await pAjax({
        url: '../server/kill.php',
        data: { pid: 1 }
    });
    var { data } = foot_list;
    var str1 = '';
    data.forEach(item => {
        str1 += `
    <img src="${item.imgpath}" alt="">`
    });
    foot.innerHTML = str1;
    var username = getCookie('username')

    function getNum() {
        var data = localStorage.getItem('data');

        var trr = JSON.parse(data);
        var trr = trr.map(v => {
            if (v.username === username) {
                return v.num
            }
        });
        // alert(trr)
        // console.log(trr);
        var alll = 0;
        for (var i = 0; i < trr.length; i++) {
            alll += parseInt(trr[i])
        }
        // alert($('.login .qwe').text())
        //获取购物车的数量
        $('.login .qwe').text("(" + alll + ")")
    }
    getNum();
}
layer.close(loadIndex)

getIndex()